<template>
  <div>
    <form>
      <label>姓名：</label>
      <input type="text" v-model.trim="obj.name" /><br /><br />

      <label>年龄：</label>
      <input type="number" v-model.trim="obj.age" /><br /><br />

      <label>身高：</label>
      <input type="number" v-model.trim="obj.high" />(米)<br /><br />

      <label>体重：</label>
      <input type="number" v-model.trim="obj.weit" />(公斤)<br /><br />

      <label>病史：</label>
      <input type="text" v-model.trim="obj.after" /><br /><br />

      <button @click.prevent="sum">诊断</button>
    </form>

    <p v-show="isshow">患者{{ uname }} 的诊断结果：{{ diagnosis }}</p>
  </div>
</template>

<script>
export default {
  data() {
    return {
      isshow: false,
      uname:'',
      diagnosis: "",
      obj: {
        name: "",
        age: "",
        high: "",
        weit: "",
        after: "",
      },
    }
  },
  methods: {
    sum() {
      const sum = this.obj.weit / (this.obj.high * this.obj.high)
      let bmi = sum ? sum : ""
      if (bmi === "") return
      if (bmi < 18.5) {
        this.diagnosis = "体重过轻"
      } else if (bmi >= 18.5 && bmi < 24.9) {
        this.diagnosis = "正常"
      } else if (bmi >= 24.9 && bmi < 29.9) {
        this.diagnosis = "体重过重"
      } else {
        this.diagnosis = "肥胖"
      }
      this.uname = this.obj.name
      this.obj.name = ""
      this.obj.age = ""
      this.obj.high = ""
      this.obj.weit = ""
      this.obj.after = ""
      this.isshow = true
    },
  },
}
</script>
